package com.hc.pingtan.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hc.pingtan.mapper.QsMembersMapper;
import com.hc.pingtan.model.QsMembers;
import com.hc.pingtan.service.IQsMembersService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author astupidcoder
 * @since 2021-11-09
 */
@Service
@DS("db2")
public class QsMembersServiceImpl extends ServiceImpl<QsMembersMapper, QsMembers> implements IQsMembersService {

    @Override
    public void createAccount(String accountName) {
        QueryWrapper<QsMembers> queryWrapper = new QueryWrapper();
        queryWrapper.eq("username", accountName);
        List<QsMembers> list = this.baseMapper.selectList(queryWrapper);
        if (!list.isEmpty()) {
            return;
        }
        String accountJson = "{\"avatars\":\"\",\"consultant\":0,\"email\":\"\",\"emailAudit\":false,\"imei\":\"\",\"invitationCode\":\"QscVBVJ9\"," +
                "\"lastLoginIp\":\"192.168.1.76:64621\",\"lastLoginTime\":1635256460,\"mobile\":\"18350108600\",\"mobileAudit\":false,\"password\":\"1be9c8d4df321ee6cd8a82a0ebaceddc\",\"pwdHash\":\"UGwpY4\",\"regAddress\":\"局域网\",\"regIp\":\"192.168.1.76:64621\",\"regSource\":true,\"regSourceCn\":\"网页端\",\"regTime\":1635256460,\"registrationId\":\"\",\"remindSmsExTime\":0,\"remindSmsTime\":0,\"robot\":0,\"secretkey\":\"\",\"sitegroupUid\":0,\"smsNum\":0,\"status\":1,\"terminal\":\"\",\"uid\":8,\"username\":\"t8600336920\",\"utype\":true}";
        QsMembers qsMembers = JSON.parseObject(accountJson, QsMembers.class);
        qsMembers.setUsername(accountName);
        qsMembers.setMobile(accountName);
        qsMembers.setUid(null);
        qsMembers.setPassword("1be9c8d4df321ee6cd8a82a0ebaceddc");
        qsMembers.setPwdHash("UGwpY4");
        this.baseMapper.insert(qsMembers);
    }
}
